
// pages/user/evaluate/evaluate.js
const urls = require('../../../utils/url.js').urls;
const http = require('../../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tx:'',
    nc:'',
    checked:'../../../image/user/gxH.png',
    nm:'1',
    pj:'无可挑剔',
    num:5,
    one_1: '',
    two_1: '',
    ms:'',

  },
  bindchecked:function(event){
  
    if (this.data.checked =='../../../image/user/gxH.png'){
      this.setData({
        checked: '../../../image/user/gxL.png',
        nm:'0'
      })
    }else{
      this.setData({
        checked: '../../../image/user/gxH.png',
        nm: '1'
      })
    }
     
  },
  //情况二:用户给评分
  in_xin: function (e) {
    var in_xin = e.currentTarget.dataset.in;
    var one_1;
    if (in_xin === 'use_sc2') {
      one_1 = Number(e.currentTarget.id);
    } else {
      one_1 = Number(e.currentTarget.id) + this.data.one_1;
    }
    this.setData({
      one_1: one_1,
      two_1: 5 - one_1
    })
    console.log(one_1)
    if (one_1==1){
       this.setData({
         pj:'很差'
       })
    } else if (one_1 == 2) {
      this.setData({
        pj: '一般'
      })
    } else if (one_1 == 3) {
      this.setData({
        pj: '满意'
      })
    } else if (one_1 == 4) {
      this.setData({
        pj: '非常满意'
      })
    } else if (one_1 == 5) {
      this.setData({
        pj: '无可挑剔'
      })
    }

  },
  fromSubmit: function (event) {
    var that = this
    var one_1 = that.data.one_1
    var nm = that.data.nm
    var ms = event.detail.value.ms
    var nc = that.data.nc

    var param = {
      stars: one_1,                                          //星级
      nm: nm,
      describe :ms  ,                                             //描述
      pjr: nc,                                            //评价人
      id: wx.getStorageSync('gdid')                                          //order_id  工单的id
    }; 
    http(urls.evaluate, param,function(res){
      wx.setStorageSync('gdzt', 3)
      console.log(res)
      if(res.code==0){
        wx.redirectTo({
          url: '../../user/work_detail/work_detail',
        })
        wx.showToast({
          title: res.msg,
        })
      }
    })



  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    
    //:展示后台给的评分
    that.setData({
      one_1: this.data.num,
      two_1: 5 - this.data.num
    })

    wx.showNavigationBarLoading();
    var param = {
      openid: app.globalData.openid                                           //openId

    };
    http(urls.details, param, function (res) {
      console.log(res)
      that.setData({
        nc: res.data.nickname,
        tx: res.data.avatarurl,
      })
      wx.hideNavigationBarLoading();
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})